<?php
/**
* @version		$Id: mod_unread.php 6534 2007-02-08 16:19:16Z pasamio $
* @package		Joomla
* @copyright	Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

global $task;
define ( 'SPACERCHAR' , ' | ' );

$hidemainmenu = JRequest::getVar('hidemainmenu');
// Initialize some variables
$config		=& JFactory::getConfig();
$user		=& JFactory::getUser();
$db			=& JFactory::getDBO();
$lang		=& JFactory::getLanguage();
$session	=& JFactory::getSession();

$sid	= $session->getId();

$output = array();

$showdiv = intval( $params->get( 'showdiv', 1 ) );

// Legacy Mode
if (defined('_J_LEGACY'))
{
	$output[] = '<span class="legacy-mode">'.JText::_('Legacy').': '._J_LEGACY.'</span>';
}


$database =& JFactory::getDBO();
$mosConfig_live_site =  $mainframe->getCfg('live_site');//TODO NiK :: yeah we'll change soon..'
	$database->setQuery("SELECT * FROM #__extension_icons"
						. "\n WHERE published = 1"
					    . "\n ORDER BY ordering");
	$rows = $database->loadObjectList();

	foreach ( $rows as $row )
	{
		$Line = '';
		if ( $showdiv ) $Line .= '<div>';

		$Line .= '<a href="' . $mosConfig_live_site . '/administrator/index.php?'
		 . $row->admin_menu_link . '">'
		 . '<img src="' . $mosConfig_live_site . '/includes/' . $row->admin_menu_img . '"'
		 . ' align="middle" border="0"'
		 . ' alt="' . $row->admin_menu_alt . '"'
		 . ' title="' . $row->admin_menu_alt . '"'
		 . ' /></a>';

		$Line .= ( $showdiv ? '</div>' : ' ' );
		$output[] = $Line;
	}//foreach

	//echo SPACERCHAR;

/*
 * Print the preview button
 */
if ( $params->get ( 'showexternalpreview' ) )
{
	$output[] = '<a href="'.$mainframe->getSiteURL().'" target="_blank" title="'.JText::_('Preview').'">' .
			'<img src="../includes/js/ThemeOffice/preview.png" align="middle" border="0" /></a> ';
}		

//die();
/*
if ($unread) {
	echo "<a href=\"index.php?option=com_messages\" style=\"color: red; text-decoration: none;  font-weight: bold\">$unread <img src=\"images/mail.png\" align=\"middle\" border=\"0\" alt=\"". JText::_( 'Mail' ) ."\" /></a>";
} else {
	echo "<a href=\"index.php?option=com_messages\" style=\"color: black; text-decoration: none;\">$unread <img src=\"images/nomail.png\" align=\"middle\" border=\"0\" alt=\"". JText::_( 'Mail' ) ."\" /></a>";
}
*/
// Get the number of unread messages in your inbox
	if ( $params->get ( 'showunread' ) )
	{
$query = 'SELECT COUNT(*)'
. ' FROM #__messages'
. ' WHERE state = 0'
. ' AND user_id_to = '.$user->get('id');
$db->setQuery( $query );
$unread = $db->loadResult();

if (JRequest::getVar('hidemainmenu')) {
	$inboxLink = '<a>';
} else {
	$inboxLink = '<a href="index.php?option=com_messages">';
}

// Print the inbox message
if ($unread) {
	$output[] = $inboxLink
			.'<img src="images/mail.png" align="middle" border="0" alt="Mail" title="Mail" />'.$unread.'</a> ';
} else {
	$output[] = $inboxLink
			.'<img src="images/nomail.png" align="middle" border="0" alt="No Mail" title="No Mail" />'.$unread.'</a> ';
}
	}//if show
	
// Get the number of logged in users
$query = 'SELECT COUNT( session_id )'
. ' FROM #__session'
. ' WHERE guest <> "1"'
;
$db->setQuery($query);
$online_num = intval( $db->loadResult() );

//Print the logged in users message
$output[] = '<img src="images/users.png" align="middle" border="0" alt="Online Users" title="OnlineUsers" />'.$online_num.' ';


if ($task == 'edit' || $task == 'editA' || JRequest::getVar('hidemainmenu') ) {
	 // Print the logout message
	 $output[] = '<img src="images/publish_x.png" align="middle" border="0" alt="Logout" title="Logout" />' .
	 		JText::_('Logout');
} else {
	// Print the logout message
	$output[] = '<img src="images/publish_x.png" align="middle" border="0" alt="Logout" title="Logout" />' .
		'<a href="index.php?option=com_login&task=logout">'.JText::_('Logout').'</a>';
}

// reverse rendering order for rtl display
if ( $lang->isRTL() ) {
	$output = array_reverse( $output );
}

// output the module
foreach ($output as $item)
{
	echo $item;
}

?>
